#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""index controller"""
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render
from django.http import HttpResponse
import json


def index(request):
    """
    返回带有数据的from表单信息
    :param request:
    :return:
    """
    if request.method == 'GET':
        return render(request, 'app/index.html', {'name': 'maomao'})


@csrf_exempt
def case_form(request):
    """
    from表单信息
    :param request:
    :return:
    """
    if request.method == 'POST':
        name = request.POST['name']
        pwd = request.POST['pwd']
        data = {'fruit': ['苹果', '橘子', '香蕉']}
        return HttpResponse(json.dumps({'data': data, 'name': name, 'pwd': pwd}), content_type='application/json')


@csrf_exempt
def get_Info(request):
    """
    获取form表单提交的信息
    :param request:
    :return:
    """
    if request.method == 'POST':
        name = request.POST['name']
        pwd = request.POST['pwd']
        data = {'fruit': ['苹果', '橘子', '香蕉']}
        return HttpResponse(json.dumps({'data': data, 'name': name, 'pwd': pwd}), content_type='application/json')
